package com.oracle.intelagr.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oracle.intelagr.common.PageModel;
import com.oracle.intelagr.entity.BAirmonitoring;
import com.oracle.intelagr.entity.BAirmonitoringExample;
import com.oracle.intelagr.entity.BAirmonitoringExample.Criteria;
import com.oracle.intelagr.mapper.BAirmonitoringMapper;
import com.oracle.intelagr.service.IAirmoniService;

@Service
public class AirmoniServiceImpl implements IAirmoniService{
	@Autowired
	private BAirmonitoringMapper airMoniMapper;
	@Override
	public void query(PageModel pageModel, Map map) {
		BAirmonitoringExample example = new BAirmonitoringExample();
		Criteria cri = example.createCriteria();
		if(map.get("startMoniorDate")!=null) {
			cri.andMonitordateGreaterThanOrEqualTo((Date)map.get("startMoniorDate"));
		}
		if(map.get("endMoniorDate")!=null) {
			cri.andMonitordateLessThanOrEqualTo((Date)map.get("endMoniorDate"));
		}
		cri.andDeleteflagEqualTo("N");
		PageHelper.startPage(pageModel.getPage(), pageModel.getPageSize());
		List<BAirmonitoring> selectByExample = airMoniMapper.selectByExample(example);
		PageInfo pageInfo = new PageInfo(selectByExample);
		pageModel.setResult(selectByExample);
		pageModel.setTotalCount((int)pageInfo.getTotal());
	}

	@Override
	public void save(BAirmonitoring airmoni) {
		airMoniMapper.insert(airmoni);
	}

	@Override
	public void update(BAirmonitoring airmoni) {
		airMoniMapper.updateByPrimaryKeySelective(airmoni);
	}

	@Override
	public BAirmonitoring queryById(Integer id) {
		return airMoniMapper.selectByPrimaryKey(id);
	}

	@Override
	public void delete(int[] ids) {
		if(ids!=null) {
			for(int id:ids) { 
				BAirmonitoring  airmoni = new BAirmonitoring();
				airmoni.setId(id);
				airmoni.setDeleteflag("Y");
				airMoniMapper.updateByPrimaryKeySelective(airmoni);
			}
		}
	}



}
